use criterion::{criterion_group, criterion_main, Criterion};
use arraylist::arraylist::ArrayList;

fn arraylist_new_benchmark(c: &mut Criterion) {
    c.bench_function("arraylist_new", |b| {
        b.iter(|| ArrayList::<i32>::new(16));
    });
}

fn arraylist_remove_range_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(i);
    }
    c.bench_function("arraylist_remove_range", |b| {
        b.iter(|| list.remove_range(10, 20));
    });
}

fn arraylist_remove_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(i);
    }
    c.bench_function("arraylist_remove", |b| {
        b.iter(|| list.remove(50));
    });
}

fn arraylist_clear_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(i);
    }
    c.bench_function("arraylist_clear", |b| {
        b.iter(|| list.clear());
    });
}

fn arraylist_index_of_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(i);
    }
    c.bench_function("arraylist_index_of", |b| {
        b.iter(|| list.index_of(&50));
    });
}

fn arraylist_sort_by_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(100 - i);
    }
    c.bench_function("arraylist_sort_by", |b| {
        b.iter(|| list.sort_by(|a, b| a.cmp(b)));
    });
}

fn arraylist_sort_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    for i in 0..100 {
        list.append(100 - i);
    }
    c.bench_function("arraylist_sort", |b| {
        b.iter(|| list.sort());
    });
}

fn arraylist_insert_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    c.bench_function("arraylist_insert", |b| {
        b.iter(|| list.insert(50, 42));
    });
}

fn arraylist_append_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    c.bench_function("arraylist_append", |b| {
        b.iter(|| list.append(42));
    });
}

fn arraylist_prepend_benchmark(c: &mut Criterion) {
    let mut list = ArrayList::new(100);
    c.bench_function("arraylist_prepend", |b| {
        b.iter(|| list.prepend(42));
    });
}

criterion_group!(
    benches,
    arraylist_new_benchmark,
    arraylist_remove_range_benchmark,
    arraylist_remove_benchmark,
    arraylist_clear_benchmark,
    arraylist_index_of_benchmark,
    arraylist_sort_by_benchmark,
    arraylist_sort_benchmark,
    arraylist_insert_benchmark,
    arraylist_append_benchmark,
    arraylist_prepend_benchmark
);
criterion_main!(benches);